home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C21 / RandGenTest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  742 b   |  28 lines

  1. //: C21:RandGenTest.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // A little test of the random number generator
  7. #include <algorithm>
  8. #include <vector>
  9. #include <iostream>
  10. #include <functional>
  11. #include <cstdlib>
  12. #include <ctime>
  13. using namespace std;
  14.  
  15. int main() {
  16.   const int sz = 10000;
  17.   int v[sz];
  18.   srand(time(0)); // Seed the random generator
  19.   for(int i = 0; i < 300; i++) {
  20.     // Using a naked pointer to function:
  21.     generate(v, v + sz, std::rand);
  22.     int count = count_if(v, v + sz, 
  23.       bind2nd(greater<int>(), RAND_MAX/2));
  24.     cout << (((double)count)/((double)sz)) * 100
  25.       << ' ';
  26.   }
  27. } ///:~
  28.